using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace 水库上位机
{
    public class ULightControl : Control
    {
        private Color onColor = Color.Green;
        private Color offColor = Color.Red;
        private bool isOn = false;

        [Category("外观")]
        [Description("开启颜色")]
        public Color OnColor
        {
            get { return onColor; }
            set 
            {
                onColor = value;
                this.Invalidate();
            }
        }

        [Category("外观")]
        [Description("关闭颜色")]
        public Color OffColor
        {
            get { return offColor; }
            set 
            {
                offColor = value;
                this.Invalidate();
            }
        }

        [Category("行为")]
        [Description("是否开启")]
        public bool IsOn
        {
            get { return isOn; }
            set 
            {
                isOn = value;
                this.Invalidate();
            }
        }

        public ULightControl()
        {
            this.DoubleBuffered = true;
            this.ResizeRedraw = true;
            this.Size = new Size(20, 20);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            // 绘制阴影
            using (Brush shadowBrush = new SolidBrush(Color.FromArgb(50, Color.Black)))
            {
                g.FillEllipse(shadowBrush, 2, 2, this.Width - 2, this.Height - 2);
            }

            // 绘制指示灯
            using (Brush brush = new SolidBrush(isOn ? onColor : offColor))
            {
                g.FillEllipse(brush, 0, 0, this.Width - 1, this.Height - 1);
            }

            // 绘制边框
            using (Pen pen = new Pen(Color.Black, 1))
            {
                g.DrawEllipse(pen, 0, 0, this.Width - 1, this.Height - 1);
            }

            // 绘制高光效果
            using (Brush highlightBrush = new SolidBrush(Color.FromArgb(100, Color.White)))
            {
                g.FillEllipse(highlightBrush, 3, 3, this.Width / 2, this.Height / 2);
            }
        }
    }
}